﻿using ConfExpert.Forms.Base;
using DevExpress.Utils;
using DevTeam;

using System;
using System.Drawing;

namespace ConfExpert.Forms.SatinAlma.YeniYapi
{
    public partial class FaturaSec : XForm
    {
        int VendorId;
        public FaturaSec(int VendorId)
        {
            InitializeComponent();
            this.VendorId = VendorId;
        }

        private void FaturaSec_Load(object sender, EventArgs e)
        {
            

            gridView1.Init("GetFaturaSec", VendorId);
            gridView1.SetCaptions("AlisFaturasiId:#");
            gridView1.FormatAsNumber(1, "FaturaToplami");
            gridView1.AddSummary();
            gridView1.MakeRowSelectable();
            gridView1.MakeReadOnly();
            gridView1.DoubleClick += gridView1_DoubleClick;
            gridView1.RowCellStyle+=gridView1_RowCellStyle;
            gridView1.BestFitColumns();

            bbiYeniOlustur.ItemClick += bbiYeniOlustur_ItemClick;
        }

        void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            switch (e.Column.FieldName)
            {
                case "InvoiceNo":
                case "FaturaNo":
                    e.Appearance.Font = new Font(AppearanceObject.DefaultFont, FontStyle.Bold);
                    break;
            }

        }

        void bbiYeniOlustur_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            using (YeniFatura yya = new YeniFatura(VendorId))
            {
                if (yya.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    AlisFaturasiId = yya.AlisFaturasiId;
                    if (AlisFaturasiId > 0)
                        this.DialogResult = System.Windows.Forms.DialogResult.OK;
                }
            }
        }

        //void bbiSonra_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        //{
        //    AlisFaturasiId = ExecScalar("InsFaturaGecici", VendorId).ToInt();
        //    if (AlisFaturasiId > 0)
        //        this.DialogResult = System.Windows.Forms.DialogResult.OK;
        //}

        public int AlisFaturasiId;
        void gridView1_DoubleClick(object sender, EventArgs e)
        {
            AlisFaturasiId = gridView1.GetFocusedDataRow()["AlisFaturasiId"].ToInt();
            if (AlisFaturasiId > 0)
                this.DialogResult = System.Windows.Forms.DialogResult.OK;

        }
    }
}
